package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Clazz;
import com.itheima.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.List;

@Mapper
public interface ClazzMapper {

    Page<Clazz> selectClazzs(EmpQueryParam cqp);

    /**
     * 新增班级
     * @param clazz
     */
    @Insert("insert into clazz(name,room,begin_date,end_date,master_id,subject,create_time,update_time)values(#{name},#{room},#{beginDate},#{endDate},#{masterId},#{subject},#{createTime},#{updateTime})")
    void insertClazz(Clazz clazz);

    /**
     * 根据id查询对应班级
     * @param id
     * @return
     */
    @Select("select * from clazz where id = #{id}")
    Clazz selectClazz(Integer id);

    void updateClazz(Clazz clazz);

    /**
     * 分组查询学生表中有哪些clazz_id,只要有就说明该班级有学生，删除时not in就能防止删除，
     * 再使用id = #{id} 来限定只删除删除的那个
     * @param id
     */
    @Delete("delete from clazz where id = #{id} and id not in (select clazz_id  from student group by clazz_id)")
    void delete(Integer id);

    /**
     * 新增学院接口中查询班级接口
     * @return
     */
    @Select("select * from clazz")
    List<Clazz> selectClazzName();


    Clazz selectClazzByName(@Param("name") String name,@Param("id") Integer id);

    void batchInsert(@Param("list") List<Clazz> list);

    void batchDelete(@Param("idList") List<Integer> idList);

    List<Clazz> batchSelectByIds(@Param("idList") List<Integer> idList);
}
